﻿using UnityEngine;
using System.Collections;

[RequireComponent(typeof(PlayerPhysics))]
public class PlayerController : MonoBehaviour
{
    public PlayerPhysics physics;
    public GunScript gun;
    void Start()
    {
        physics = GetComponent<PlayerPhysics>();
        gun = GetComponentInChildren<GunScript>();
    }
    void LateUpdate()
    {
        float horDir = Input.GetAxisRaw("Horizontal");
        physics.MoveHorizontal(horDir);
        //float vertDir = Input.GetAxisRaw("Vertical");
        //physics.MoveVertical(vertDir);
        if (Input.GetButtonDown("Jump"))
            physics.Jump();
        if (Input.GetKeyDown(KeyCode.LeftControl))
        {
            //gun.Shoot(physics.charDirection);
        }
    }


    #region seb
    // Use this for initialization
    //public float speed;
    //public float acceleration;
    //public float gravity = 0;
    //public float jump = 25;
    //public float targetSpeed;
    //public float currentSpeed;

    //public Vector2 amountToMove;

    //PlayerPhysics physics;
    //void Start()
    //{
    //    physics = GetComponent<PlayerPhysics>();
    //}

    //// Update is called once per frame
    //void Update()
    //{
    //    targetSpeed = Input.GetAxisRaw("Horizontal") * speed;
    //    currentSpeed = IncrementTowards(currentSpeed, targetSpeed, acceleration);

    //    amountToMove.x = currentSpeed * Time.deltaTime;
    //    amountToMove.y -= gravity * Time.deltaTime;
    //    if(physics.landed==true)
    //    {
    //        if(Input.GetButtonDown("Jump"))
    //        {
    //            amountToMove.y = jump * Time.deltaTime ;
    //            physics.landed = false;
    //        }
    //    }
    //    physics.Move(amountToMove);
    //}
    //public float IncrementTowards(float current, float target, float accel)
    //{
    //    if (current == target)
    //        return current;
    //    else
    //    {
    //        float dir = Mathf.Sign(target - current);
    //        current += accel * Time.deltaTime * dir;

    //        return (dir == Mathf.Sign(target - current)) ? current : target;
    //    }
    //}
    #endregion
}
